//
//  UIButton+Extension.m
//  Weibo-OC
//
//  Created by 焦林生 on 15/11/20.
//  Copyright © 2015年 cn.baidu. All rights reserved.
//

#import "UIButton+Extension.h"

@implementation UIButton (Extension)

/**
 *  UIButton
 *
 *  @param norImage          图像
 *  @param highImage
 *  @param backImageNameNor  图像背景
 *  @param backImageNameHigh
 *
 *  @return UIButton
 */
+ (UIButton *)norImage:(NSString *)norImage highImage:(NSString *)highImage backImageNameNor:(NSString *)backImageNameNor backImageNameHigh:(NSString *)backImageNameHigh {
    
    UIButton *btn = [[UIButton alloc] init];
    
    [btn setImage:[UIImage imageNamed:norImage] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    
    [btn setBackgroundImage:[UIImage imageNamed:backImageNameNor] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:backImageNameHigh] forState:UIControlStateHighlighted];
    
    [btn sizeToFit];
    
    return btn;
}

/**
 *  UIButton类扩展
 *
 *  @param title         title
 *  @param color         color
 *  @param fontSize      size
 *  @param backImageName 背景图像名称
 *
 *  @return UIButton
 */
+ (UIButton *)title:(NSString *)title color:(UIColor *)color fontSize:(CGFloat )fontSize backImageName:(NSString *)backImageName {    UIButton *button = [[UIButton alloc]init];

    NSString *s = [NSString stringWithFormat:@"%@_highlighted",backImageName];
    
    [button setTitle:title forState: UIControlStateNormal];
    [button setTitleColor:color forState: UIControlStateNormal];
    
    button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    
    [button setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:s] forState:UIControlStateHighlighted];
    
    [button sizeToFit];
    return button;
}



@end
